<template>
	<div>
		<h1>login</h1>
		<div>
			<input type="text" v-model="uName"/>
			<input type="text" v-model="uPwd"/>
			<input type="button" value="提交" @click="send"/>
		</div>
	</div>
</template>

<script>
	export default {
		data () {
			return {
				uName : '',
				uPwd : ''
			}
		},
		created() {
			this.auto_login()
		},
		mounted() {
			
		},
		methods:{
			async send () {
				let data = {
					uName :this.uName,
					uPwd: this.uPwd
				}
				data = JSON.stringify(data)
				const { data: res } = await this.$http.post('/user/v1/login',data)
				if (res.code == '200') {
					localStorage.setItem('token',res.data)
					console.log(res.data)
					 this.$router.push('/home')
				}
			},
			async auto_login() {
				let token = localStorage.token
				if (token) {
					const { data: res } = await this.$http.get('/user/v1/auto_login')
					console.log(res)
					if (res.code == 200) {
						
						this.$router.push('/home')
					}
				}
			}
		}	
	}
</script>

<style>
</style>
